import request from '@/utils/request'
// 查询案件调解过程中的材料接口
const aprv_process_materials_Api = {
  list: '/aprv_process_materials/list',
  getById: '/aprv_process_materials/getMaterialByApplyId',
  getAllById: '/aprv_process_materials/getAllMaterialByApplyId',
  upload: '/aprv_process_materials/saveMaterial',
  uploadMulti: '/aprv_process_materials/saveMaterialMulti',
  deleteMaterial: '/aprv_process_materials/deleteMaterial',
  validateMaterial: '/processapprove/passRecord',
  queryDocumentByApplyId: '/aprv_process_materials/queryDocumentByApplyId',
  uploadArrive: '/aprv_process_materials/saveMaterialArrive',
  uploadCustomer: '/aprv_process_materials/saveMaterialCustomer',
  queryNoArchiveCustomerMaterial: '/aprv_process_materials/queryNoArchiveCustomerMaterial', // 查询未归档的数据
  screenMaterials: '/aprv_process_materials/screenMaterials' // 分屏展示材料
}

/**
 * 查询案件调解过程中的已经上传传材料接口 API接口
 * @param {aprv_process_materials_Api} body
 * @returns
 */
export function getMaterialsList (body) {
  return request({
    url: aprv_process_materials_Api.list,
    method: 'post',
    data: body
  })
}

/**
 * 查询案件调解过程中的已经上传传材料接口 API接口
 * @param {aprv_process_materials_Api} body
 * @returns
 */
export function getMaterialByApplyId (body) {
  return request({
    url: aprv_process_materials_Api.getById,
    method: 'post',
    data: body
  })
}

/**
 * 查询案件调解过程中的已经上传传材料接口 API接口
 * @param {aprv_process_materials_Api} parameter
 * @returns
 */
export function getAllMaterialByApplyId (parameter) {
  return request({
    url: aprv_process_materials_Api.getAllById,
    method: 'post',
    params: parameter
  })
}

/**
 * 通过applID校验文件是否上传完全
 * @param {*} parameter
 * @returns
 */
export function validateMaterial (parameter, body) {
  return request({
    url: aprv_process_materials_Api.validateMaterial,
    method: 'post',
    params: parameter,
    data: body
  })
}

/**
 * 案件调解过程中的上传传材料接口 API接口 -单个文件上传
 * @param {aprv_process_materials_Api} data
 * @returns
 */
export function saveMaterial (parameter, data) {
    var body = new FormData()
    body.append('file', data)
    return request({
      url: aprv_process_materials_Api.upload,
      headers: { 'Conten-Type': 'mulitpart/form-data' },
      method: 'post',
      params: parameter,
      data: body
    })
}

/**
 * 案件调解过程中的上传传材料接口 API接口  -重复文件上传
 * @param {aprv_process_materials_Api} fileList
 * @returns
 */
export function saveMaterialRepeat (parameter, fileList) {
  var body = new FormData()
  if (fileList != undefined && fileList.length > 0) {
      fileList.forEach(item => {
          body.append('files', item)
      })
      return request({
        url: aprv_process_materials_Api.uploadMulti,
        headers: { 'Conten-Type': 'mulitpart/form-data' },
        method: 'post',
        params: parameter,
        data: body
      })
  }
}

/**
 * 案件调解过程中的上传传材料接口 API接口 -删除对应的文件
 * @param {aprv_process_materials_Api} data
 * @returns
 */
export function deleteMaterial (parameter) {
  return request({
    url: aprv_process_materials_Api.deleteMaterial,
    headers: { 'Conten-Type': 'mulitpart/form-data' },
    method: 'post',
    params: parameter
  })
}

/**
 * 系统文书查询接口
 * @param {aprv_process_materials_Api} data
 * @returns
 */
export function queryDocumentByApplyId (parameter) {
  return request({
    url: aprv_process_materials_Api.queryDocumentByApplyId,
    method: 'post',
    params: parameter
  })
}

/**
 * 案件送达过程的上传传材料接口 API接口  -重复文件上传
 * @param {aprv_process_materials_Api} data
 * @returns
 */
export function saveMaterialArrive (parameter, fileList) {
  var body = new FormData()
  if (fileList != undefined && fileList.length > 0) {
    fileList.forEach(item => {
        body.append('files', item)
    })
    return request({
      url: aprv_process_materials_Api.uploadArrive,
      headers: { 'Conten-Type': 'mulitpart/form-data' },
      method: 'post',
      params: parameter,
      data: body
    })
  }
}

/**
 * 自定义材料类型文件上传接口
 * @param {*} parameter
 * @param {*} fileList
 * @returns
 */
export function saveMaterialCustomer (parameter, fileList) {
  var body = new FormData()
  if (fileList != undefined && fileList.length > 0) {
      fileList.forEach(item => {
          body.append('files', item)
      })
      return request({
        url: aprv_process_materials_Api.uploadCustomer,
        headers: { 'Conten-Type': 'mulitpart/form-data' },
        method: 'post',
        params: parameter,
        data: body
      })
  }
}

/**
 * 查询未归档的数据
 * @param {*} parameter
 */
export function queryNoArchiveCustomerMaterial (parameter) {
  return request({
    url: aprv_process_materials_Api.queryNoArchiveCustomerMaterial,
    method: 'post',
    params: parameter
  })
}

/**
 * 分屏展示对应案件涉及的各个环节的文件的资料
 * @param {*} applyid
 * @returns
 */
export function screenMaterials (applyid) {
  return request({
    url: aprv_process_materials_Api.screenMaterials,
    method: 'post',
    params: { 'applyid': applyid }
  })
}
